package org.gg.boom.modules.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.servlet.http.HttpServletResponse;
import org.gg.boom.common.controller.BaseController;
import org.gg.boom.common.model.Response;
import org.gg.boom.common.utils.poi.ExcelUtil;
import org.gg.boom.kernel.annotation.Log;
import org.gg.boom.kernel.enums.BusinessType;
import org.gg.boom.modules.sys.model.param.SysOperLogParam;
import org.gg.boom.modules.sys.model.vo.SysOperLogResult;
import org.gg.boom.modules.sys.service.SysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 操作日志记录
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController {
    @Autowired
    private SysOperLogService operLogService;

    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public Response list(SysOperLogParam param) {
        Page<SysOperLogResult> page = operLogService.selectOperLogList(param);
        return getDataTable(page);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOperLogParam param) {
        Page<SysOperLogResult> page = operLogService.selectOperLogList(param);
        ExcelUtil<SysOperLogResult> util = new ExcelUtil<>(SysOperLogResult.class);
        util.exportExcel(response, page.getRecords(), "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/{operIds}")
    public Response remove(@PathVariable Long[] operIds) {
        return toResponse(operLogService.deleteOperLogByIds(operIds));
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    public Response clean() {
        operLogService.cleanOperLog();
        return success();
    }
}
